package com.shuoyue.ycgk.ui.recruitment.resume.major;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.google.android.flexbox.FlexboxLayoutManager;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.baseadapter.AppBaseQuickAdapter;
import com.shuoyue.ycgk.entity.Major;
import com.shuoyue.ycgk.entity.MajorType;
import com.shuoyue.ycgk.utils.SizeUtil;
import com.shuoyue.ycgk.utils.SpacesItemDecoration;

import java.util.List;

public class MajorTypeAdapter extends AppBaseQuickAdapter<MajorType> {
    SelectCallback selectCallback;

    public MajorTypeAdapter(@Nullable List<MajorType> data, SelectCallback selectCallback) {
        super(R.layout.item_major_type, data);
        this.selectCallback = selectCallback;
    }

    @Override
    protected void convert(BaseViewHolder helper, MajorType item) {
        helper.addOnClickListener(R.id.name);
        helper.setText(R.id.name, item.getName());
        RecyclerView recyclerView = helper.getView(R.id.recycleView);
        helper.setGone(R.id.recycleView, item.isSelect());
        helper.setImageResource(R.id.indication, item.isSelect() ?
                R.mipmap.icon_arrow_up : R.mipmap.icon_arrow_down);


        recyclerView.setLayoutManager(new FlexboxLayoutManager(mContext));
        if (recyclerView.getTag() == null) {
            recyclerView.addItemDecoration(new SpacesItemDecoration(SizeUtil.dip2px(mContext, 4), false));
            recyclerView.setTag("tag");
        }
        MajorAdapter adapter = new MajorAdapter(item.getMajors());
        recyclerView.setAdapter(adapter);
        adapter.setOnItemChildClickListener((adapter1, view, position) -> {
            Major major = (Major) adapter1.getItem(position);
            if (selectCallback != null) {
                selectCallback.select(major.getName());
            }
        });

    }


    public interface SelectCallback {
        void select(String name);
    }

}
